﻿using System;
using System.Collections.Generic;
using System.Windows.Documents;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using ReportingFramework;
using WorkItemReportInterface;

namespace MSFforAgileSoftwareDevelopmentv50
{
    /// <summary>
    /// Interaction logic for MSFforAgileSoftwareDevelopmentv50Template.xaml
    /// </summary>
  public partial class MSFforAgileSoftwareDevelopmentv50Template : Report, IWorkItemReport
  {
      public MSFforAgileSoftwareDevelopmentv50Template()
      {
        InitializeComponent();
      }
      public FixedDocument Create(IEnumerable<WorkItem> data)
      {
        var rows = new List<object>();
        foreach (var workItem in data)
        {
          if (workItem.Type.Name == "User Story")
          {
            rows.Add(new ProductBacklogItemCardRow(workItem));
          }
          else if (workItem.Type.Name == "Task")
          {
            rows.Add(new TaskCardRow(workItem));
          }
          else if (workItem.Type.Name == "Bug")
          {
            rows.Add(new BugCardRow(workItem));
          }
          else
          {
            rows.Add(new UnknownCardRow(workItem));
          }
        }

        return GenerateReport(
          page => new PageInfo(page, DateTime.Now),
          rows
          );
      }

    public string TeamFoundationServerTemplate()
    {
      return "MSF for Agile Software Development v5.0";
    }

    /// <summary>
    /// This class becomes the data context for every page. It gives the page 
    /// access to the page number.
    /// </summary>
    public class PageInfo
    {
      public PageInfo(int pageNumber, DateTime reportDate)
      {
        PageNumber = pageNumber;
        ReportDate = reportDate;
      }

      public bool IsFirstPage { get { return PageNumber == 1; } }
      public int PageNumber { get; set; }
      public DateTime ReportDate { get; set; }
    }
  }
}
